package taller2.controller.modes;

import java.awt.event.MouseEvent;

import javax.swing.JOptionPane;

import taller2.interfaces.Graph;
import taller2.utils.Utils;
import taller2.view.draws.DrawingArea;

public class RandomGraphMode implements Mode {
	private Graph graph;
	
	// constructor
	public RandomGraphMode(Graph graph){
		this.graph = graph;
	}
	
	// when the mouse is pressed a random graph is created
	public void whenPressed(MouseEvent arg0, DrawingArea area) {
		area.getDrawer().unselectNode();
		
		String vert = JOptionPane.showInputDialog ("Enter number of vertices"); 
		String conn = JOptionPane.showInputDialog ("Enter number of connections"); 
	
		boolean areNotEmpty = (vert != null)&&(conn != null);
		boolean areNumbers = Utils.isANumber(vert) && Utils.isANumber(conn);
		if (areNotEmpty&&areNumbers)
			graph.randomGraph(Integer.parseInt(vert),Integer.parseInt(conn));
	
		area.repaint();
	}


	public void whenReleased(MouseEvent arg0, DrawingArea area) {}

	public void whenDragged(MouseEvent arg0, DrawingArea area) {}

}
